package cn.lzh.controller;

import cn.lzh.entity.BookType;
import cn.lzh.service.BooktypeService;
import cn.lzh.tool.RespJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@CrossOrigin//允许跨域
@RestController
@RequestMapping("/api/adm/type")
public class BooktypeController {
@Autowired
    BooktypeService booktypeService;
    @RequestMapping("/findAll")//查询全部
    public Map<String, Object> findAll(){
   List<BookType> list=booktypeService.findAll();
    return  RespJson.pack(200,"ok",list);
}


@RequestMapping("/add")
public Map<String,Object>add(int id,BookType booktype){
        if (id==0){//0表示添加
            booktypeService.add(booktype);
        }
        if(id>=0){//》=0 表示=修改
           booktypeService.update(booktype);
        }
    List<BookType> lst =booktypeService.findAll();
    return RespJson.pack(200,"添加成功",lst);
}



@RequestMapping("/findByid/{id}")//根据id查询
    public Map<String,Object> findById(@PathVariable Integer  id){
    BookType byId = booktypeService.findById(id);
        return  RespJson.pack(200,"ok",byId);
}
}
